package mock.servicesdirectory.test.dao;

import java.util.List;

import mock.servicesdirectory.common.entities.UserInfo;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;


public class UserDao extends HibernateDaoSupport implements IUserDao {

	@SuppressWarnings("unchecked")
	public boolean isAuthentication(String userName, String password) {
		boolean isAuthen = false;
		String sql = "from UserInfo";
		List<UserInfo> rs = (List<UserInfo>)this.getSessionFactory().getCurrentSession().createQuery(sql).list();
		for(int i=0; i<rs.size(); i++){
			if(rs.get(i).getUserName().trim().equals(userName.trim())
				&& rs.get(i).getPassword().trim().equals(password.trim())){
				isAuthen = true;
			}
		}
		return isAuthen;
	}

	public List<UserInfo> getUserInfos() {
		String sql = "from UserInfo";
		return getHibernateTemplate().find(sql);
		
	}

}
